<#include "/common/taglibs.ftl" />
<@menu code='${entityName!}'/>
<title><@spring.message code="${entityName!}" /> - <@spring.message code="${op}" /></title>
<div class="m-portlet">
    <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
            <div class="m-portlet__head-title">
                <span class="m-portlet__head-icon">
                    <i class="flaticon-calendar"></i>
                </span>
                <h3 class="m-portlet__head-text m--font-primary">
                    <@spring.message code="${entityName!}" /> / <@spring.message code="${op}" />
                    <#if op != 'op.view'>
                    （<@spring.message code="reuqired.tips"/>）
                    </#if>
                </h3>
            </div>
        </div>
        <@formHeaderButtons resourceIdentity='${resourceIdentity!}' baseUrl='${baseUrl!}'/>
    </div>
    <!--begin::Form-->
    <form class="m-form m-form--fit m-form--label-align-right" method="post" id="mainForm">
        <div class="m-portlet__body">
            <div class="m-form__content">
                <@showFieldErrors commandName="m" />
                <#include "/common/taglibs/validationMessage.ftl">
            </div>
            <input type="hidden" class="form-control" id="id" name="id" value="${(m.id)!}"/>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.name"/><span class="required"> * </span></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" name="name" value="${(m.name)!}" required/>
                    <span class="m-form__help"><@spring.message code="user.name.tips"/></span>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.enName"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" name="enName" value="${(m.enName)!}" />
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.loginName"/><span class="required"> * </span></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" id="loginName" name="loginName" value="${(m.loginName)!}" />
                    <span class="m-form__help"><@spring.message code="user.loginName.tips"/></span>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.password"/><#if op == 'op.add'><span class="required"> * </span></#if></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="password" placeholder="" class="form-control" id="password" name="plainPassword" value="" />
                    <span class="m-form__help"><@spring.message code="user.password.tips"/></span>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.password.confirm"/><#if op == 'op.add'><span class="required"> * </span></#if></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="password" placeholder="" class="form-control" id="password" name="passwordConfirm" value="" />
                    <span class="m-form__help"><@spring.message code="user.password.confirm.tips"/></span>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.email"/><span class="required"> * </span></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" id="email" name="email" value="${(m.email)!}" >
                    <span class="m-form__help"> <@spring.message code="user.email.tips"/> </span>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.mobile"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <input type="text" placeholder="" class="form-control" name="mobile" value="${(m.mobile)!}" >
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="user.gender"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <@radio name="gender" items=genders/>
                </div>
            </div>
            <div class="form-group m-form__group row">
                <label class="col-form-label col-lg-3 col-sm-12"><@spring.message code="activated"/></label>
                <div class="col-lg-4 col-md-9 col-sm-12">
                    <@switchButton inputName="activated" on=m.activated />
                </div>
            </div>
        </div>
        <@formFooterButtons resourceIdentity='${resourceIdentity!}' baseUrl='${baseUrl!}'/>
    </form>
    <!--end::Form-->
</div>
<page-plugin-style>
</page-plugin-style>
<page-plugin-script>
</page-plugin-script>
<page-style></page-style>
<page-script>
	<script>
		jQuery(document).ready(function() {
			var $form = $("#mainForm")
    		$.m.form.initValue("gender", "${(m.gender)!}");
    		$.m.form.initValue("activated", "${(m.activated)!?string('true','false')}");
			<#if op == 'op.view'>
	        	$.m.form.readonly($form, false);
			</#if>
		    $.m.form.validate($form, {
		    	rules: {
	                name: {
	                    minlength: 2,
	                    required: true
	                },
	                loginName:{
	                	minlength: 4,
	                    required: true,
	                    remote: {
	                      url: "${ctx}/${baseUrl!}/validate",
	                      type: "post",
	                      data: {
	                    	field:"loginName",
	                    	fieldValue: function() {
	                          return $("#loginName").val();
	                        },
	                        id: function() {
	                          return $("#id").val();
	                        }
	                      }
	                    }
	                },
	                plainPassword:{
	                	<#if op == 'op.add'>
	                	required: true,
	                	</#if>
	                	minlength: 6
	                },
	                passwordConfirm:{
	                	<#if op == 'op.add'>
	                	required: true,
	                	</#if>
	                	equalTo: "#password"
	                },
	                email:{
	                	required: true,
	                	email: true,
	                    remote: {
	                      url: "${ctx}/${baseUrl!}/validate",
	                      type: "post",
	                      data: {
	                    	field:"email",
	                    	fieldValue: function() {
	                          return $("#email").val();
	                        },
	                        id: function() {
	                          return $("#id").val();
	                        }
	                      }
	                    }
	                }
		    	},
		    	messages: {
		    		loginName:{
		    			remote:'<@spring.message code="user.invalid.loginName.occupied"/>'
		    		},
		    		email:{
		    			remote:'<@spring.message code="user.invalid.email.occupied"/>'
		    		}
		    	}
		    });
		});
	</script>
</page-script>